import React from "react";
import { Button, message, Row, Col } from "antd";

const LogController = () => {
  const startLogging = async () => {
    if (!(window as any).electronAPI?.startLogCollection) {
      message.error("当前环境不支持日志功能");
      return;
    }
    const res = await (window as any).electronAPI.startLogCollection();
    console.log(res);
    message.success(res.success ? "日志已启动" : `错误: ${res.error}`);
  };

  const stopLogging = async () => {
    if (!(window as any).electronAPI?.stopLogCollection) {
      message.error("当前环境不支持日志功能");
      return;
    }
    const res = await (window as any).electronAPI.stopLogCollection();
    console.log(res);
    message.success(res.success ? "日志已停止" : `错误: ${res.error}`);
  };

  return (
    <Row gutter={8} style={{ marginBottom: 16 }}>
      <Col>
        <Button type="primary" onClick={startLogging} size="small">
          启动日志
        </Button>
      </Col>
      <Col>
        <Button danger onClick={stopLogging} size="small">
          停止日志
        </Button>
      </Col>
    </Row>
  );
};

export default LogController;